home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / c-runtime / include / objc-protoP.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-21  |  6.8 KB  |  240 lines

  1. /* -*-c-*- */
  2.  
  3. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* As a special exception, if you link this library with files
  22.    compiled with GCC to produce an executable, this does not cause
  23.    the resulting executable to be covered by the GNU General Public License.
  24.    This exception does not however invalidate any other reasons why
  25.    the executable file might be covered by the GNU General Public License.  */
  26.  
  27. /* 
  28.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/include/RCS/objc-protoP.h,v 1.1 1992/04/13 11:40:53 dennisg Exp dennisg $
  29.   $Author: dennisg $
  30.   $Date: 1992/04/13 11:40:53 $
  31.   $Log: objc-protoP.h,v $
  32.  * Revision 1.1  1992/04/13  11:40:53  dennisg
  33.  * Initial revision
  34.  *
  35.  * Revision 0.11  1991/12/31  20:16:08  dennisg
  36.  * Deleted index variable stuff.  Index variables are a hack to the language.
  37.  * Cleaned up some documentation.
  38.  *
  39.  * Revision 0.10  1991/12/10  12:03:22  dennisg
  40.  * Cleaned up file format for a distribution.
  41.  *
  42.  * Revision 0.9  1991/12/01  01:29:29  dennisg
  43.  * modified to remove changes previously made to
  44.  * implement posing.  posing just got easy.
  45.  *
  46.  * Revision 0.8  1991/11/29  22:00:10  dennisg
  47.  * modified to implement set functions.
  48.  *
  49.  * Revision 0.7  1991/11/29  20:02:01  dennisg
  50.  * fixed several const decls.  bozo.
  51.  *
  52.  * Revision 0.6  1991/11/29  13:32:16  dennisg
  53.  * committed some functions to inline and changes prototypes
  54.  * to match.
  55.  * also added some documentation.
  56.  *
  57.  * Revision 0.5  1991/11/29  00:24:14  dennisg
  58.  * many changes including posing, things to make the compiler
  59.  * happier, structure changes, and things to make it play better.
  60.  *
  61.  * Revision 0.4  1991/11/19  12:37:49  dennisg
  62.  * modified to support changes of run-time.
  63.  *
  64.  * Revision 0.3  1991/11/16  15:56:07  dennisg
  65.  * deleted some prototypes that are no longer part of the
  66.  * implementation.
  67.  * added others.
  68.  *
  69.  * Revision 0.2  1991/11/07  22:31:42  dennisg
  70.  * added copyleft.
  71.  *
  72.  * Revision 0.1  1991/10/24  00:19:24  dennisg
  73.  * Initial check in.  Preliminary development stage.
  74.  *
  75.  */
  76.  
  77.  
  78. #ifndef _objc_protop_INCLUDE_GNU
  79. #define _objc_protop_INCLUDE_GNU
  80.  
  81. #include    <stdio.h>
  82.  
  83. #include    <tm.h>
  84.  
  85. #include  <objc.h>
  86.  
  87.  
  88. /*
  89.  * Add a class to the class hash table and assign it a class number. 
  90.  */
  91. void
  92. addClassToHash(Class_t aClass);
  93.  
  94. /*
  95.  * This function takes a list of methods and adds them to the method list of
  96.  * a class.  The method list must remain intact during the lifetime of the
  97.  * class. 
  98.  */
  99. void  
  100. addMethodsToClass (Class_t, MethodList_t);
  101.  
  102. /*
  103.  * This function creates a new instance of aClass, initializes its isa
  104.  * instance variable to point to the class, and return the new instance.  
  105.  *
  106.  * All other instance variables are initialized to 0. 
  107.  */
  108. static inline id  
  109. class_createInstance( Class_t aClass) {
  110.  
  111.   return (*_alloc)(aClass);
  112. }
  113.  
  114. /*
  115.  * object_dispose() frees the memory occupied by aObject after setting its
  116.  * isa instance variable to nil, and returns nil.  The function it calls to
  117.  * do this work can be changed by reassigning the _dealloc variable. 
  118.  */
  119. static inline id  
  120. object_dispose (id aObject) {
  121.   
  122.   return (*_dealloc)(aObject);
  123. }
  124.  
  125. /*
  126.  * object_copy() creates a new object that's an exact copy of anObject and
  127.  * return the new object.  The second argument, indexedIvarBytes, specifies
  128.  * the number of additional bytes that should be allocated for the copy to
  129.  * accommodate indexed instance variables; it serves the same purpose as the
  130.  * second argument to class_createInstance().  The function that
  131.  * object_copy() calls to do this work can be changed by reassigning the
  132.  * _copy variable. 
  133.  */
  134. static inline id  
  135. object_copy (id aObject) {
  136.  
  137.   return (*_copy)(aObject);
  138. }
  139.  
  140. /*
  141.  * object_realloc() reallocates storage for anObject, adding numBytes if
  142.  * possible.  The memory previously occupied by anObject is freed if it can't
  143.  * be reused, and a pointer to the new location of anObject is returned.  The
  144.  * function that object_realloc() calls to do this work can be changed by
  145.  * reassigning the _realloc variable. 
  146.  */
  147. static inline id  
  148. object_realloc (id aObject, u_int numBytes) {
  149.  
  150.   return (*_realloc)(aObject, numBytes);
  151. }
  152.  
  153. /*
  154.  * This function causes one class to pose as its super class.  Messages sent
  155.  * to the super class will actually be sent to the posing class. 
  156.  *
  157.  * Instance variables should not be declared in the posing class.  The posing
  158.  * class can add new methods to the class or override existing methods in the
  159.  * super class. 
  160.  */
  161. Class_t 
  162. class_poseAs(Class_t, Class_t);
  163.  
  164.  
  165. /* These functions set and return the class version number. */
  166. static inline void 
  167. class_setVersion(Class_t aClass, long theVersion) {
  168.  
  169.   aClass->version = theVersion ;
  170.   aClass->isa->version = theVersion ;
  171. }
  172.  
  173. static inline long
  174. class_getVersion(Class_t aClass) {
  175.  
  176.   return aClass->version ;
  177. }
  178.  
  179.  
  180. /*
  181.  * Class numbers are stored in the class's info variable. This is temporary. 
  182.  * Eventually we will allocate a member to the class so that some efficiency
  183.  * can be gained by not shifting. 
  184.  */
  185. #define    CLASS_LOCATION_SHIFT (BITS_PER_WORD / 2)
  186.  
  187. static inline void
  188. setClassNumber (Class_t aClass, u_int aNumber) {
  189.  
  190.  
  191.   aClass->info |= aNumber << CLASS_LOCATION_SHIFT;
  192. }
  193.  
  194. static inline u_int
  195. getClassNumber (Class_t aClass) {
  196.  
  197.  
  198.   return aClass->info >> CLASS_LOCATION_SHIFT;
  199. }
  200.  
  201.  
  202. /*
  203.  * These functions add and remove methods in a list from a class.  These
  204.  * functions perform the actual work required for those functions.  
  205.  *
  206.  * The appropriate run-time is to provide the user callable functions to
  207.  * perform these functions.  Typically those functions perform something
  208.  * specific to their run-time type and call these functions to perform the 
  209.  * actual work.
  210.  */ 
  211. void  
  212. class_removeMethods (Class_t aClass, MethodList_t aMethodList);
  213.  
  214. /*
  215.  * Find the named method in a linked list of methods. 
  216.  */
  217. Method_t  
  218. searchForMethodInList (MethodList_t aList, const char* selName);
  219.  
  220. /*
  221.  * fprintf() is used id we're debugging.  If DEBUG isn't defined then this
  222.  * def isn't defined thereby causing the compiler to eliminate the parameter
  223.  * decl. 
  224.  */
  225. #ifdef DEBUG
  226. #define DEBUG_PRINTF  fprintf
  227. #else
  228. #define DEBUG_PRINTF
  229. #endif
  230.  
  231.  
  232. /*
  233.  * Function that dumps information about all of the classes to stdout. 
  234.  */
  235. void
  236. debug_dump_classes(void);
  237.  
  238. #endif
  239.  
  240.